﻿#region Librerias

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ESF.Web;
using ESF.MSReporting;

#endregion


public partial class Reports_Users_frmUserReports : ESF.Web.Pages.BasePage
{
	#region Propiedades

	public string ReportPath
	{
		get
		{
			return Request.QueryString["ReportPath"];
		}
	}
	
	#endregion
	
	
	#region Page Events
	
	protected void Page_Load(object sender, EventArgs e)
    {
		if (!IsPostBack)
		{
			// Validar parametro diligenciado
			if (string.IsNullOrEmpty(ReportPath))
			{
				btnConsultar.Enabled = false;
				JS.AddWarning(Page, "Falta la ruta del reporte");
				return;
			}

			#region Habilitar Campos

			switch (ReportPath.ToUpper ())
			{
				case "~/REPORTS/USERS/OPERATIONEXECUTIONSTATISTICS":
					pnlFechaInicio.Visible = true;
					pnlFechaFin.Visible = true;
				break;

				case "~/REPORTS/USERS/USERSESSIONS":
					pnlUserLogin.Visible = true;
					pnlFechaInicio.Visible = true;
					pnlFechaFin.Visible = true;
				break;

				case "~/REPORTS/USERS/USERSESSIONHISTORYDETAIL":
					pnlGeneral.Visible = false;
					Consultar ();
				break;
			}

			#endregion
		}
    }

	#endregion


	#region Metodos

	private void Consultar()
	{
		#region Parametros

		ReportParams parameters;


		parameters = new ReportParams(true);

		parameters.AddString("Login", "pUserAlias", txtUserLogin.Text);
		
		switch (ReportPath.ToUpper ())
		{
			case "~/REPORTS/USERS/OPERATIONEXECUTIONSTATISTICS":
			case "~/REPORTS/USERS/USERSESSIONS":
				parameters.AddStartDate(lblTitleFechaInicio.Text, "pStartDate", txtFechaInicio.Text);
				parameters.AddEndDate(lblTitleFechaFin.Text, "pEndDate", txtFechaFin.Text);
			break;

			case "~/REPORTS/USERS/USERSESSIONHISTORYDETAIL":
				parameters.AddString("UserAlias", "pUserAlias", Request.QueryString ["pUserAlias"]);
			break;
		}

		#endregion


		MSReportingHelper.ShowLocalReportIframeBasic (
			ifrReportViewer, ReportPath, "~/Reports/frmReportViewer.aspx",
			parameters.ReportingParams,
			parameters.ReportingParams);

		updResults.Update();
	}


	private void Limpiar()
	{
		txtUserLogin.Text = string.Empty;
		txtFechaInicio.Text = string.Empty;
		txtFechaFin.Text = string.Empty;

		MSReportingHelper.HideReportIframe(ifrReportViewer);
	}

	#endregion


	#region Eventos

	protected void btnConsultar_Click(object sender, EventArgs e)
	{
		Consultar();
	}


	protected void btnLimpiar_Click(object sender, EventArgs e)
	{
		Limpiar();
	}

	#endregion
}